package com.hdsx.jxcsxm.party.controller;

import com.hdsx.jxcsxm.party.bean.BaseBean;
import com.hdsx.jxcsxm.party.bean.PartyAccessBean;
import com.hdsx.jxcsxm.party.bean.Xmtjbean;
import com.hdsx.jxcsxm.party.server.OriginServer;
import com.hdsx.jxcsxm.party.server.PartyAccessServer;
import com.hdsx.jxcsxm.utile.JsonUtils;
import com.hdsx.jxcsxm.utile.ResultReturn;
import com.hdsx.webutil.struts.BaseActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * @author 占贤银
 * time 2024/3/5 11:12
 * description 生命之灯因热情而点燃，生命之舟因拼搏而前行
 */
@Controller
@Scope("prototype")
public class PartyAccessController extends BaseActionSupport implements ModelDriven<PartyAccessBean> {

    private PartyAccessBean partyAccessBean = new PartyAccessBean();

    @Resource(name = "partyAccessServerImpl")
    private PartyAccessServer partyAccessServer;

    @Resource(name = "originServerImpl")
    private OriginServer originServer;

    @Override
    public PartyAccessBean getModel() {
        return partyAccessBean;
    }

    public void queryAll(){
        try {
            List<PartyAccessBean> results = partyAccessServer.queryAll();
            JsonUtils.write(results, getresponse().getWriter());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void pushDataToHallPlatform() throws Exception {
        ResultReturn results = new ResultReturn();
        PartyAccessBean partyAccessBean = new PartyAccessBean();
        partyAccessBean.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        try {
            // todo 资金到位数据推送到厅平台
//            List<BaseBean> params = originServer.queryJxscxmZjdwAll();
//            boolean zjdwBl = partyAccessServer.addZjdwForPlatform(params);
//
//            // todo 资金拨付数据推送到厅平台
//            final List<BaseBean> zjbfParams = originServer.queryJxcsxmZjbfAll();
//            final boolean zjbfBl = partyAccessServer.addZjbfForPlatform(zjbfParams);

            // todo 项目调剂
//            List<Xmtjbean> tjParams = originServer.queryXmtjAll();
//            boolean xmtjBl = partyAccessServer.addXmtjForPlatform(tjParams);

            // todo 结余资金
            List<Xmtjbean> jyzjParams = originServer.queryXmjyzjAll();
            boolean jyzjBl = partyAccessServer.addXmjyzjForPlatform(jyzjParams);

//            // todo 项目状态
//            List<Xmtjbean> xmztParams = originServer.queryXmztAll();
//            boolean xmztBl = partyAccessServer.addXmztForPlatform(xmztParams);
////
////            // todo 资金调剂
//            List<BaseBean> zjtjParams= originServer.queryJxcsxmZjtjAll();
//            boolean xmzjBl = partyAccessServer.addXmzjtjForPlatform(zjtjParams);

            if (jyzjBl) {
//             if (zjdwBl && zjbfBl && jyzjBl && xmztBl && xmzjBl) {
                partyAccessBean.setResult("成功");
                partyAccessBean.setContent("推送36.2.6.17中间库【项目状态、资金到位、资金拨付、资金调剂、资金结余】");
                results.setCode(200);
                results.setMsg("推送成功");
            } else {
                partyAccessBean.setResult("失败");
                partyAccessBean.setContent("推送36.2.6.17中间库【项目状态、资金到位、资金拨付、资金调剂、资金结余】");
                results.setCode(400);
                results.setMsg("推送失败");
            }
        } catch (Exception e) {
            partyAccessBean.setResult("失败");
            partyAccessBean.setContent("推送36.2.6.17中间库【项目状态、资金到位、资金拨付、资金调剂、资金结余】");
            partyAccessBean.setFailure(e.getMessage());
            results.setCode(400);
            e.printStackTrace();
            results.setMsg("推送失败，原因：" + e.getMessage());
        }
        boolean bl = originServer.addTaskLog(partyAccessBean);

        JsonUtils.write(results, getresponse().getWriter());
    }
}
